--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit b84ade45f85f685ba96b829bf0e9afcb5b014079
Parents : 9f04aef
Author : Ivan <ivan@quad4.io>
Signature : Signature validation error
Date : 2026-05-09T01:03:59-05:00
fix(meshchat, health_monitor): add garbage collection calls to cleanup resources during context teardown and health checks
Changes
2 files changed, 4 insertions(+), 0 deletions(-)
Diff
diff --git a/meshchatx/meshchat.py b/meshchatx/meshchat.py
index 1367e5f9..5a5ceacd 100644
--- a/meshchatx/meshchat.py
+++ b/meshchatx/meshchat.py
@@ -850,6 +850,7 @@ class ReticulumMeshChat:
if identity_hash in self.contexts:
del self.contexts[identity_hash]
self.current_context = None
+ gc.collect()
def _teardown_all_contexts_for_reload(self):
# Stop per-identity long-running services before tearing down contexts.
@@ -879,6 +880,7 @@ class ReticulumMeshChat:
self.contexts.clear()
self.current_context = None
self.running = False
+ gc.collect()
async def _send_rns_reload_status(
self,
diff --git a/meshchatx/src/backend/recovery/health_monitor.py b/meshchatx/src/backend/recovery/health_monitor.py
index 5a631005..93d2ca14 100644
--- a/meshchatx/src/backend/recovery/health_monitor.py
+++ b/meshchatx/src/backend/recovery/health_monitor.py
@@ -12,6 +12,7 @@ from in-memory deques kept by PersistentLogHandler and psutil.
import asyncio
import collections
+import gc
import json
import logging
import threading
@@ -59,6 +60,7 @@ class HealthMonitor:
self._check()
except Exception as exc:
_log.debug("HealthMonitor check error: %s", exc)
+ gc.collect()
await asyncio.sleep(self.CHECK_INTERVAL)
def _check(self):
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────